{smcl}
{* 30Jan2007}{...}
{hline}
{hi:help ivactest}{right:(SJ7-4: st0030_3)}
{hline}

{title:Title}

{p2colset 5 17 19 2}{...}
{p2col:{hi:ivactest} {hline 2}}Perform Cumby-Huizinga test for autocorrelation after IV/OLS estimation{p_end}
{p2colreset}{...}


{title:Syntax}

{p 8 14 2}{cmd:ivactest}
{bind:[{cmd:,} {cmd:q(}{it:#}{cmd:)}}
{bind:{cmd:s(}{it:#}{cmd:)}]}

{pstd}{cmd:ivactest} is for use after {helpb ivreg2}, {helpb ivregress},
{helpb regress}, and {helpb newey}.

{pstd}
{cmd:ivactest} is for use with time-series data.  You must {cmd:tsset} your
data before using {cmd:ivactest}; see {manhelp tsset TS}. You may apply
{cmd:ivactest} to one time series of a panel dataset.


{title:Description}

{pstd}{cmd:ivactest} performs the general specification test of serial
correlation proposed by Cumby and Huizinga (1992) after ordinary least squares
(OLS) or instrumental variables (IV) estimation. In their words, the null
hypothesis of the test is that the regression error is a moving average (MA) of
known order q>=0 against the general alternative that autocorrelations of the
regression error are nonzero at lags greater than q.  The test is general
enough to test the hypothesis that the regression error has no serial
correlation (q=0) or the null hypothesis that serial correlation in the
regression error exists but dies out at a known finite lag (q>0).

{pstd} The test is especially attractive because it can be used in three
frequently encountered cases where alternative such as the Box-Pierce test
({helpb wntestq}), Durbin's h test
({helpb regress postestimationts##durbinalt:estat durbinalt})
and the Breusch-Godfrey test
({helpb regress postestimationts##bgodfrey:estat bgodfrey}) are
not applicable. One of these cases is the presence of endogenous regressors,
which renders each of these tests invalid. A second case involves the
overlapping data commonly encountered in financial markets where the
observation interval is shorter than the holding period, which requires the
estimation of the induced MA process. The Cumby-Huizinga test
avoids estimation of the MA process by utilizing only the sample
autocorrelations of the residuals and a consistent estimate of their asymptotic
covariance matrix. The third case involves conditional heteroskedasticity of
the regression error term, which is also handled without difficulty by the
Cumby-Huizinga test.

{pstd} If the prior estimation command estimated a VCE under the assumption of
independently and identically distributed errors, the Cumby-Huizinga statistic
becomes the Breusch-Godfrey statistic for the same number of autocorrelations
and will return the same result as {cmd:estat bgodfrey}. That special case of
the test was first derived by Sargan in an unpublished working paper in 1976,
cited by Cumby and Huizinga (fn. 13).

{pstd}{cmd:ivactest} can be used after OLS regression with {cmd:regress},
{cmd:newey}, {cmd:ivregress}, or {cmd:ivreg2} (Baum, Schaffer and Stillman
2003).


{title:Options}

{p 4 8 2}{cmd:q(}{it:#}{cmd:)} specifies the lowest lag order to be tested. By
default, {cmd:q(0)}. A {it:#} greater than 0 cannot be used if the previous
command estimated a VCE under the assumption of independently and identically
distributed errors.

{p 4 8 2}{cmd:s(}{it:#}{cmd:)} specifies the number of lag orders to be tested.
By default, {cmd:s(1)}.

{pstd}The default test is a test with the null hypothesis that the residuals
are nonautocorrelated versus the alternative that they exhibit AR(1).  The
parameters s and q may be used to test any sequence of autocorrelations. For
instance, {cmd:q(4) s(4)} tests the null hypothesis that autocorrelations 5-8
of the residual process are jointly zero, allowing autocorrelations 1-4 to take
on any value.


{title:Saved results}

{pstd}{cmd:ivactest} saves the value of the test statistic, its p-value, and
the degrees of freedom of the test. It also saves the minimum and maximum lag
tested.  See {cmd:return list}.


{title:Examples}

{p 8 12 2}{stata "use http://www.stata-press.com/data/r9/lutkepohl.dta" : . use http://www.stata-press.com/data/r9/lutkepohl.dta }{p_end}

{p 8 12 2}{stata "regress investment income " : . regress investment income }

{p 8 12 2}{stata "ivactest" : . ivactest}{p_end}

{p 8 12 2}{stata "regress investment income, robust " : . regress investment income, robust}

{p 8 12 2}{stata "ivactest, s(4)" : . ivactest, s(4)}{p_end}

{p 8 12 2}{stata "newey investment income, lag(4) " : . newey investment income, lag(4)}

{p 8 12 2}{stata "ivactest, s(8)" : . ivactest, s(8)}{p_end}

{p 8 12 2}{stata "ivreg2 investment ( income= lconsumption lincome) " : . ivreg2 investment ( income= lconsumption lincome)}

{p 8 12 2}{stata "ivactest, s(2)" : . ivactest, s(2)}{p_end}

{p 8 12 2}{stata "ivactest, s(4)" : . ivactest, s(4)}{p_end}

{p 8 12 2}{stata "ivreg2 investment ( income= lconsumption lincome), gmm " : . ivreg2 investment ( income= lconsumption lincome), gmm}

{p 8 12 2}{stata "ivactest, q(4) s(4)" : . ivactest, q(4) s(4)}{p_end}


{title:References}

{p 4 8 2}Baum, C. F., M. E. Schaffer, and S. Stillman. 2003.
Instrumental variables and GMM: Estimation and testing.
Stata Journal 3: 1-31.

{p 4 8 2}Baum, C. F., M. E. Schaffer, and S. Stillman. 2007.
Enhanced routines for instrumental variables/GMM estimation and testing.
Boston College Department of Economics Working Paper No. 667.

{p 4 8 2}Cumby, R. E., and J. Huizinga. 1992.
Testing the autocorrelation structure of disturbances in ordinary least
squares and instrumental variables regressions. 
{it:Econometrica} 60: 185-195.


{title:Authors}

{pstd}Christopher F Baum, Boston College, USA{p_end}
{pstd}baum@bc.edu{p_end}

{pstd}Mark E. Schaffer, Heriot-Watt University, UK{p_end}
{pstd}m.e.schaffer@hw.ac.uk{p_end}


{title:Citation}

{pstd}{cmd:ivactest} is not an official Stata command. It is a free
contribution to the research community, like a paper. Please cite it as such:
{p_end}

{phang}Baum, C.F., and M. E. Schaffer.  2007.
ivactest: Stata module to perform Cumby-Huizinga test for autocorrelation
after IV/OLS estimation. Boston College Department of Economics, Statistical
Software Components S456841. Downloadable from 
{browse "http://ideas.repec.org/c/boc/bocode/s456841.html":http://ideas.repec.org/c/boc/bocode/s456841.html}{p_end}


{title:Also see}

{psee}Manual:  {hi:[R] regression postestimation}{p_end}

{psee}Online:  {helpb ivreg2}, {helpb ivhettest}, {helpb ivendog} (if installed)
{p_end}
